package com.jingbian.cppccbackend.mapper.admin;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jingbian.cppccbackend.entity.Admins;
import com.jingbian.cppccbackend.entity.Department;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * <p>
 * 用户信息表 Mapper 接口
 * </p>
 *
 * @author yezi
 * @since 2025-02-09
 */
@Mapper
public interface SuperMapper extends BaseMapper<Department> {

    @Select("select * from propositions_departments")
    List<Department> getProList();


    @Select("select * from public_departments")
    List<Department> getPubList();

    @Insert("insert into propositions_departments(name, description) values(#{name}, #{description})")
    void addProDepartment(Department department);

    @Insert("insert into public_departments(name, description) values(#{name}, #{description})")
    void addPubDepartment(Department department);

    @Delete("delete from propositions_departments where id = #{id}")
    void deleteProDepartment(Integer id);

    @Delete("delete from public_departments where id = #{id}")
    void deletePubDepartment(Integer id);

    @Update("update admins set password = #{password}, update_time = NOW() where aid = #{aid}")
    void updatePassword(@Param("aid") Integer aid, @Param("password") String password);

    List<Admins> getAdmins(String sortType, String permissionType, String statusType, String searchText);

    @Update("update admins set status = '已注销', update_time = NOW(),logout_time = NOW() where aid = #{aid}")
    void disableAdmin(@Param("aid") Integer aid);

    Admins getAdminById(Integer aid);

    // 更新管理员信息
    void updateAdmin(Admins admin);

    // 新增普通管理员
    void addAdmin(Admins admin);


    @Select("select count(*) from admins where account = #{account}")
    int checkAccountExists(@Param("account") String account);
}
